﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace WebApplication3.Controllers
{
    public class ThongKeController : ApiController
    {
        private readonly CityDashboardEntities db = new CityDashboardEntities();

        ///// <summary>
        ///// GET api/status
        ///// </summary>
        ///// <returns>Cập nhật trạng thái hồ sơ</returns>        
        //[Route("api/thongke/hoso")]
        //public IQueryable<View_LoaiHS_trinhUB_DungHan_HPT> GetHoSo()
        //{
        //    return db.View_LoaiHS_trinhUB_DungHan_HPT;
        //}

        //[Route("api/thongke/duan")]
        //public object GetDuaAn()
        //{
        //    return new { db.View_DA_Capmoi_2014_HPT, db.View_DA_giaithe_2014_HPT };
        //}

        [Route("api/thongke")]
        public object Get()
        {
            
            var result = new Dictionary<string, object>
            {
                {"HoSo", db.View_LoaiHS_trinhUB_DungHan_HPT},
                {"DuAnCapMoi", db.View_DA_Capmoi_2014_HPT},
                {"DoanhNghiepGiaiThe", db.View_DA_giaithe_2014_HPT},
                {"SoLuongDNTheoLoaiHinhDuAn", db.ViewDADT_byTenloaiHinhDT_HPT},
                {"SoTienTheoLoaiHinhDuAn", db.ViewDADT_byTenloaiHinhDT_USD_HPT},
                {"LoaiHinhDN", db.ViewDADT_byloaiDN_HPT},
                {"Top5DN", db.view_top5DA_by_vondautuUSD_HPT},
                //Top5NDT
                {"Top5NDT", db.view_top5NDT},
                //
                {"Top10QG", db.ViewDADT_byTenQuocTich_BC_USD_HPT},
                {"DViCapPhep", db.View_DonViCapPhep_HPT},
                {"HoSoDangGiaiQuyet", db.View_HSDangGiaiQuyet_HPT},
            };

            return result;            
        }

        /*
        // GET api/View_LoaiHS_trinhUB_DungHan_HPT/5
        [ResponseType(typeof(View_LoaiHS_trinhUB_DungHan_HPT))]
        public IHttpActionResult GetView_LoaiHS_trinhUB_DungHan_HPT(int id)
        {
            View_LoaiHS_trinhUB_DungHan_HPT view_loaihs_trinhub_dunghan_hpt = db.View_LoaiHS_trinhUB_DungHan_HPT.Find(id);
            if (view_loaihs_trinhub_dunghan_hpt == null)
            {
                return NotFound();
            }

            return Ok(view_loaihs_trinhub_dunghan_hpt);
        }

        // PUT api/View_LoaiHS_trinhUB_DungHan_HPT/5
        public IHttpActionResult PutView_LoaiHS_trinhUB_DungHan_HPT(int id, View_LoaiHS_trinhUB_DungHan_HPT view_loaihs_trinhub_dunghan_hpt)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != view_loaihs_trinhub_dunghan_hpt.loai_hs)
            {
                return BadRequest();
            }

            db.Entry(view_loaihs_trinhub_dunghan_hpt).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!View_LoaiHS_trinhUB_DungHan_HPTExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }

        // POST api/View_LoaiHS_trinhUB_DungHan_HPT
        [ResponseType(typeof(View_LoaiHS_trinhUB_DungHan_HPT))]
        public IHttpActionResult PostView_LoaiHS_trinhUB_DungHan_HPT(View_LoaiHS_trinhUB_DungHan_HPT view_loaihs_trinhub_dunghan_hpt)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.View_LoaiHS_trinhUB_DungHan_HPT.Add(view_loaihs_trinhub_dunghan_hpt);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (View_LoaiHS_trinhUB_DungHan_HPTExists(view_loaihs_trinhub_dunghan_hpt.loai_hs))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = view_loaihs_trinhub_dunghan_hpt.loai_hs }, view_loaihs_trinhub_dunghan_hpt);
        }

        // DELETE api/View_LoaiHS_trinhUB_DungHan_HPT/5
        [ResponseType(typeof(View_LoaiHS_trinhUB_DungHan_HPT))]
        public IHttpActionResult DeleteView_LoaiHS_trinhUB_DungHan_HPT(int id)
        {
            View_LoaiHS_trinhUB_DungHan_HPT view_loaihs_trinhub_dunghan_hpt = db.View_LoaiHS_trinhUB_DungHan_HPT.Find(id);
            if (view_loaihs_trinhub_dunghan_hpt == null)
            {
                return NotFound();
            }

            db.View_LoaiHS_trinhUB_DungHan_HPT.Remove(view_loaihs_trinhub_dunghan_hpt);
            db.SaveChanges();

            return Ok(view_loaihs_trinhub_dunghan_hpt);
        }
        */
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }

        private bool View_LoaiHS_trinhUB_DungHan_HPTExists(int id)
        {
            return db.View_LoaiHS_trinhUB_DungHan_HPT.Count(e => e.loai_hs == id) > 0;
        }
    }
}